package com.bbs.manage.controller;

import com.bbs.domain.Word;
import com.bbs.entity.PageResult;
import com.bbs.service.WordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName WordController
 * @Description TODO
 * @Author chen hong wei
 * @Date 2019/9/21 15:34
 */

@RestController
@RequestMapping("/word")
public class WordController {

    @Autowired
    private WordService wordService;

    @GetMapping("/findAll")
    public List<Word> findAll() {
        List<Word> list = wordService.findList();
        return list;
    }

    /**
     * @return com.bbs.entity.PageResult<com.bbs.domain.Word>
     * @author chen hong wei
     * @Description 分页
     * @Date 22:07 2019/9/21
     * @Param [page]
     **/
    @GetMapping("/findByPage")
    public PageResult<Word> findPage(int page) {
        //健壮信判断
        if (page <= 0) {
            page = 1;
        }
        if (page > 3) {
            page = 1;
        }
        //每页显示  条数
        int size = 6;
        PageResult<Word> words = wordService.findPage(page, size);
        return words;
    }

    @GetMapping("/delete")
    public void delete(Integer id) {
        wordService.delete(id);
    }

    @PostMapping("/insert")
    public void insert(@RequestBody Word word){
        wordService.insert(word);
    }

    @GetMapping("/update")
    public void update(Integer wordid,int status){
        wordService.update(wordid,status);
    }
}